package com.whcoding.mybatis.page.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whcoding.mybatis.page.entity.OrmDeptPO;
import com.whcoding.mybatis.page.mapper.OrmDeptMapper;
import com.whcoding.mybatis.page.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: spring-boot-learning
 * @description:
 * @author: whcoding
 * @create: 2022-03-08 09:37
 **/
@Service
public class DeptServiceImpl implements DeptService {

	@Autowired
	private OrmDeptMapper deptMapper;

	@Override
	public List<OrmDeptPO> queryAllDept() {
		return deptMapper.selectAll();
	}

	/**
	 * 分页查询数据
	 *
	 * @return
	 */
	@Override
	public PageInfo<OrmDeptPO> page() {
		int currentPage = 1;
		int pageSize = 5;
		String orderBy = "id desc";
		int count = deptMapper.selectCount(null);
		System.out.println("数据count=" + count);

		//1.设置当前页以及页码
		PageHelper.startPage(currentPage, pageSize);
		//2.查询数据
		List<OrmDeptPO> deptPOS = deptMapper.selectAll();
		//3.通过PageInfo对象获取分页信息 当前页码 总页数，以及总条数
		PageInfo<OrmDeptPO> deptPageInfo = new PageInfo<>(deptPOS);
		return deptPageInfo;
	}
}
